#![windows_subsystem = "windows"]
#![cfg(windows)]
extern crate libloading;
use libloading::os::windows::*;

mod i_result;
mod lib_create;
pub use i_result::IResult;

fn main() {
    // 设置日志目录
    {
        let file_name = std::env::current_exe()
            .unwrap()
            .file_stem()
            .unwrap()
            .to_str()
            .unwrap()
            .to_string();
        let mut log_dir = std::env::current_dir().unwrap_or(std::path::PathBuf::from("log_dir"));
        log_dir.push(format!("{}_logs", file_name));
        std::env::set_var("log_dir", log_dir);
    }

    // 加载主程序动态库
    let map = lib_create::generate_dll_list();
    let val = map
        .get("stock_info_watch.dll")
        .expect("stock_info_watch.dll 找不到路径");
    let lib: Library = Library::new(val).expect("stock_info_watch.dll 加载失败");

    // 运行main方法
    unsafe {
        let function: Symbol<unsafe fn()> = lib.get(b"main").expect("function");
        function();
    }
}
